<template>
  <div class="bg">
    <div class="login-content shadow">
      <ChangeLanguage />
      <p class="t-c">{{title}}</p>
      <el-form :model="ruleForm" ref="ruleForm" @keyup.enter.native="submit">
        <el-form-item prop="userName" :rules="[V.required]">
          <FInput v-model.trim="ruleForm.userName" :maxlength="10" width="100%" icon="el-icon-user" :placeholder="$t('placeholder.Please enter user name')" :autofocus="true"/>
        </el-form-item>
        <el-form-item prop="password" :rules="[V.required, V.password]">
          <FInput v-model.trim="ruleForm.password" :maxlength="10" width="100%" icon="el-icon-unlock" :placeholder="$t('placeholder.Please enter password')" :password="true" />
        </el-form-item>
        <!-- <p class="c-gray">用户名密码随意填写</p> -->
        <el-button type="primary" @click="submit" :loading="loading">{{$t('button.Login')}}</el-button>
      </el-form>
    </div>
  </div>
</template>

<script>
import ChangeLanguage from '@/components/i18n/change-language'
import FInput from '@/components/form/f-input'
import V from '@/assets/scripts/validate'
import MENU from '@/assets/scripts/menu.js' // 菜单如果从后台获取-需删除此文件
import { initMenuRouter } from '@/router'
// import { login } from '@/api/public'

export default {
  components: { ChangeLanguage, FInput },
  data() {
    return {
      V,
      loading: false,
      title: process.env.NAME,
      // 表单相关
      ruleForm: {
        userName: '',
        password: ''
      }
    }
  },
  mounted() {
    sessionStorage.removeItem('TAGS_LIST')
    this.$store.commit('SET_TOKEN', '')
    this.$store.commit('SET_MENU', [])
  },
  methods: {
    /**
     * 登录
     */
    submit() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          // 请求后台
          this.$store.commit('SET_USER', { userName: this.ruleForm.userName })
          this.$store.commit('SET_TOKEN', 'tokenValue')
          this.$store.commit('SET_MENU', MENU) // 菜单如果从后台获取-需替换传入数据
          initMenuRouter()
          this.$router.replace('/home')
          /* const params = {
            userName: this.ruleForm.userName,
            password: this.ruleForm.password
          }
          this.loading = true
          login(params).then((res) => {
            this.$store.commit('SET_TOKEN', res.data.token)
            this.$store.commit('SET_MENU', MENU)
            initMenuRouter()
            this.$store.commit('SET_USER', res.data.adminInfo)
            this.$router.replace('/home')
          }).finally(() => {
            this.loading = false
          }) */
        }
      })
    }
  }
}
</script>

<style scoped lang="less">
.bg {
  width: 100vw;
  height: 100vh;
  background: var(--theme-header-background);
  > .login-content {
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: -170px;
    margin-left: -220px;
    width: 440px;
    height: 340px;
    background: #fff;
    padding: 30px;
    font-size: 22px;
    .el-form {
      margin-top: 30px;
      .el-button {
        width: 100%;
        margin-top: 20px;
      }
      /deep/ .el-icon-user,
      /deep/ .el-icon-unlock{
        font-size: 20px;
      }
    }
  }
  /deep/ .slide-verify-slider {
    font-size: 16px;
  }
}
</style>
